package br.pucrio.inf.les.SPLAnalyser.impl.squidplugin.query.metricas;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import br.ufrn.dimap.ase.squid.core.models.squidmodel.Asset;

public class Raffle {
	private List<Asset> realImpact = new ArrayList<Asset>();
	private List<Asset> raffledAssets = new ArrayList<Asset>();
	
	public Raffle(List<Asset> realImpact) {
		this.realImpact.addAll(realImpact);
		this.raffledAssets = new ArrayList<Asset>();
	}
	
	public List<Asset> now(int percent) {
		List<Asset> realImpactVolatil = new ArrayList<Asset>(realImpact);
		int raffleSize = Math.round(((float) percent / 100f) * ((float) realImpactVolatil.size()) + 0.5f) ;
		raffledAssets = new ArrayList<Asset>();
		for (int i = 0; i < raffleSize; i++) {
			Random random = new Random();
			int index = random.nextInt(realImpactVolatil.size());
			Asset raffledAsset = realImpactVolatil.get(index);
			raffledAssets.add(raffledAsset);
			realImpactVolatil.remove(index);
		}
		return raffledAssets;
	}
}
